package com.tdwyz.fictionmanage.mapper;

import com.tdwyz.fictionmanage.pojo.Chapter;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface ChapterMapper {
    /**
     * 新增章节
     * @param chapter
     * @return
     */
    @Insert("insert into chapter(fictionId,number, name, content, create_user, create_time, update_time)\n" +
            "values (#{fictionId},#{number},#{name},#{content},#{createUser},now(),now())")
    boolean insert(Chapter chapter);

    /**
     * 查询该用户的文章列表
     * @param userId
     * @return
     */
    @Select("select * from chapter where create_user = #{userId}")
    List<Chapter> list(Integer userId);

    /**
     * 获取文章详情（用户数据回显）
     * @param id
     * @return
     */
    @Select("select * from chapter where id = #{id}")
    Chapter getById(Integer id);

    /**
     * 更新章节
     * @param chapter
     * @return
     */
    @Update("update chapter set " +
            "name = #{name}," +
            "content = #{content}," +
            "update_time = now() " +
            "where id = #{id}")
    boolean update(Chapter chapter);

    /**
     * 删除章节
     * @param id
     * @return
     */
    @Delete("delete from chapter where id =#{id}")
    boolean delete(Integer id);
}
